<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="passFlag">
        <dict-select :options="dict.type.audit_type" v-model="queryParams.passFlag" placeholder="请选择审核状态"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="taskList">
      <el-table-column label="用户名" align="left" prop="userName" width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="UID" align="left" prop="userRandomId" width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="店铺名称" align="left" prop="shopName" width="140" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="带货任务" align="left" prop="taskName" width="200"/>-->
      <el-table-column label="状态" align="center" prop="passFlag" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_type" :value="scope.row.passFlag" />
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ $yun.convertTimestamp(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetails(scope.row)"
              v-hasPermi="['car:task:edit']"
            >详情
            </el-button>
            <div class="audit-group" v-if="scope.row.passFlag == 0">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-check"
                  @click="handlePass(scope.row)"
                  v-hasPermi="['car:task:edit']"
                >通过
                </el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-close"
                  @click="handleReject(scope.row)"
                  v-hasPermi="['car:task:remove']"
                >驳回
                </el-button>
              </div>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 任务详情 -->
    <el-dialog title="直播任务详情" :visible.sync="open" width="900px" append-to-body>
      <el-form>
        <el-form-item label="发布商家：" prop="shopName">
          <span>{{ details.shopName }}</span>
        </el-form-item>
        <el-form-item label="申请时间：" prop="shopName">
          <span>{{ $yun.convertTimestamp(details.createTime) }}</span>
        </el-form-item>
        <el-row class="details-row">
          <el-col :span="3" style='font-weight:bold;'>商品列表：</el-col>
        </el-row>
            <el-table :data="details.goodsChildList">
              <el-table-column label="商品名称" align="center" prop="goodsName" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="原价" align="center" prop="originalPrice" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="现价" align="center" prop="price" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="商品描述" align="center" prop="goodsDesc" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="图片" align="center" prop="image"  width="120" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <oss-image-preview :src="scope.row.image" width="40" height="40"></oss-image-preview>
                </template>
              </el-table-column>
              <el-table-column label="销量" align="center" prop="salesVolume" width="120" :show-overflow-tooltip="true"/>
              <el-table-column label="带货数量" align="center" prop="quantitySold" width="120" :show-overflow-tooltip="true"/>
            </el-table>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listTask, pass, reject } from '@/api/live/ownerTaskAudit'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import { deepClone } from '@/utils'

export default {
  name: 'Task',
  components: { DateRangePicker },
  dicts: ['audit_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺带货任务表格数据
      taskList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      details: {},

    }
  },
  created() {

    if(this.$route.query.shopName){
      this.queryParams.shopName = this.$route.query.shopName;
    }
    this.getList()
  },
  methods: {
    /** 查询店铺带货任务列表 */
    getList() {
      this.loading = true;
      let searchData = this.$deepClone(this.queryParams);
      listTask(searchData).then(response => {
        let list = response.data.records;
        this.taskList = response.data.records;
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams= {
        pageNum: 1,
          pageSize: 10
      };
      this.handleQuery()
    },
    /** 通过操作 */
    handlePass(row) {
      const ids = row.id
      this.$modal.confirm('是否确认通过店铺带货任务编号为"' + ids + '"的任务申请？').then(function() {
        return pass(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('审核成功')
      }).catch(() => {
      })
    },
    /** 驳回 */
    handleReject(row) {
      const ids = row.id
      this.$modal.confirm('是否确认驳回店铺带货任务编号为"' + ids + '"的任务申请？').then(function() {
        return reject(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('驳回成功')
      }).catch(() => {
      })
    },
    /** 查看详情*/
    handleDetails(row) {
      this.details = row;
      this.details.products = row.taskProductName.split(',');
      this.open = true
    }
  }
}
</script>
<style lang="scss" scoped>

.details-row {
  line-height: 34px;
}
.product-item {
  padding-right: 10px;
}
</style>
